Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--target-api-url support for migrate repo and org #1214

Merged
merged 14 commits into from
Jan 30, 2024

Conversation

brianaj
Copy link
Collaborator

@brianaj brianaj commented Jan 29, 2024

Part of #1094 and https://github.ghe.com/github/octoshift/issues/7956

Adds full support for migrate-repo (gei already implemented) and migrate-org commands to support --target-api-url.

Functional tested for all the above against EU. Details in https://github.ghe.com/github/octoshift/issues/7956#issuecomment-8112051.

  • Did you write/update appropriate tests
  • Release notes updated (if appropriate)
  • Appropriate logging output
  • Issue linked
  • Docs updated (or issue created)
  • New package licenses are added to ThirdPartyNotices.txt (if applicable)

Copy link

github-actions bot commented Jan 29, 2024

Unit Test Results

797 tests   797 ✅  22s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit cf1d3d9.

♻️ This comment has been updated with latest results.

@brianaj brianaj changed the title 1094 support migrate org --target-api-url support for migrate repo and org Jan 29, 2024
@brianaj brianaj marked this pull request as ready for review January 29, 2024 22:05
@brianaj brianaj requested a review from ArinGhazarian January 29, 2024 22:06
Copy link
Collaborator

@ArinGhazarian ArinGhazarian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good.
For the tests, I don't think you need to add the target api url to the command handler tests but rather you need to add a simple test for the handlers themselves to make sure that github api factory is getting invoked with the target api url.

@@ -23,6 +23,7 @@ public class MigrateRepoCommandHandlerTests
private const string ADO_REPO = "foo-repo";
private const string GITHUB_ORG = "foo-gh-org";
private const string GITHUB_REPO = "gh-repo";
private const string TARGET_API_URL = "https://api.github.com";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a comment just for this line but it applies to all tests for all CLIs.

There is no need to add the target api url here because it's only going to be used inside the Command (not the handler) to create an instance of GithubApi. Instead a new and very simple test needs to be added to the Command tests (e.g. MigrateOrgCommandTests.cs) to make sure if the --target-api-url is provided, the factory is going to receive it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests are going to be similar to this one

@brianaj brianaj requested a review from ArinGhazarian January 30, 2024 00:23
Copy link
Collaborator

@ArinGhazarian ArinGhazarian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great. There is still a missing test though 😃

@@ -21,6 +21,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(command.Options, "github-source-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "github-target-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar test to It_Uses_Target_Api_Url_When_Provided also needs to be added for this command too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay will add tomorrow, thanks for the quick feedback!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArinGhazarian added in 833931b, also note I was following the gei spec which originally added this flag, hence why I added test in handler to begin with but thanks for catching it 👍🏾 https://github.com/github/gh-gei/blob/main/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandTests.cs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a lot has changed in the CLI since then mostly because the underlying System.CommandLine nuget package pas early beta. Later on as the package became more mature, we changed the way we created the handlers to keep the handles' constructor very simple and easy to test and also keep the concerns as separate as possible so for each command we have the arg, the command and the handler, each one doing a specific thing. IMO the most interesting thing we did was to not inject factories into handlers and delegate the creation of a handler to the command via BuildHanlder and that's where all the creation logic goes.

@brianaj brianaj requested a review from ArinGhazarian January 30, 2024 20:00
@@ -21,6 +21,7 @@ public void Should_Have_Options()
TestHelpers.VerifyCommandOption(command.Options, "github-source-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "github-target-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a lot has changed in the CLI since then mostly because the underlying System.CommandLine nuget package pas early beta. Later on as the package became more mature, we changed the way we created the handlers to keep the handles' constructor very simple and easy to test and also keep the concerns as separate as possible so for each command we have the arg, the command and the handler, each one doing a specific thing. IMO the most interesting thing we did was to not inject factories into handlers and delegate the creation of a handler to the command via BuildHanlder and that's where all the creation logic goes.

@brianaj brianaj enabled auto-merge January 30, 2024 20:19
@brianaj brianaj merged commit dadf326 into main Jan 30, 2024
28 checks passed
@brianaj brianaj deleted the 1094-support-migrate-org branch January 30, 2024 20:36
Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
bbs2gh 78% 73% 647
gei 79% 70% 513
ado2gh 84% 79% 616
Octoshift 86% 75% 1246
Summary 83% (6699 / 8093) 74% (1500 / 2014) 3022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants